//轮播图
var First = $('#banner>ul').find("li").eq(0).clone();
$('#banner>ul').append(First);
var i = 3;
function dsq() {
    timer = setInterval(function () {
        i++;
        if (i > 3) {
            i = 0;
            $('#banner>ul').css({"margin-left": 0 + "px"});
            i++;
        }
        $('#banner>ul').animate({"margin-left": -656 * i + "px"});
        if (i == 3) {
            $('#dot').find("li").eq(0).addClass("red").siblings().removeClass("red");
        } else {
            $('#dot').find("li").eq(i).addClass("red").siblings().removeClass("red");
        }
    }, 3000)
}
dsq();
//格式化时间
$('body').find('[dateformat]').each(function () {
    var when = $(this).attr('dateformat');
    $(this).text(new Date(parseInt(when) * 1000).toLocaleString().split(' ')[0].replace(/年|月/g, "-").replace(/日/g, " ").replace(/\//g, "-"));
});
//用户展示
var account = Cookie.Get("account");
if (account != undefined && account != false) {
    $('#merchant_li2').hide();
    $('#merchant_li3').show();
    $('#merchant_li3 span').text(account);
}
//样式
$('#undefinedplaceholder').css({'line-height': '5px'});
var Day = new Date().getTime();
var totalnum = parseInt($("#totalnum").html());
var changelist = $("#changelist");
var typid = $('#procurement_select').val();
$('#procurement_button').click(function () {
    typid = $('#procurement_select').val();
    var ids = {}, num = 0, arr = [];
    for (var i = 0, max = totalnum > 10 ? 10 : totalnum; i < max; i++) {
        num = Math.ceil(totalnum * Math.random());
        if (!ids[num]) {
            ids[num] = num;
            arr.push(110 + num);
        } else {
            i--;
        }
    }
    new Ajax("/api/purchase/change").keyvalue('ids', arr.join(',')).keyvalue('typid', typid).getJson(function (json) {
        changelist.empty();
        $.each(json, function (idx, val) {
            var surplus = Math.ceil(val.enddt - new Date().getTime() / 1000)
            if (surplus > 0) {
                changelist.append('<tr><td purname>' + val.name + '</td><td corpname>' + val.corpname + '</td><td enddt dateformat="' + val.enddt + '">还剩' + Math.ceil(surplus / 86400) + '天</td><td oper><a href="/purchase/details/' + val.id + '">立即报价</a></td></tr>');
            } else {
                changelist.append('<tr><td purname>' + val.name + '</td><td corpname>' + val.corpname + '</td><td enddt changelist="' + val.enddt + '"></td><td oper><a>已截止</a></td></tr>');
            }
        });
    });
});
$('#change').click(function () {
    var ids = {}, num = 0, arr = [];
    for (var i = 0, max = totalnum > 10 ? 10 : totalnum; i < max; i++) {
        num = Math.ceil(totalnum * Math.random());
        if (!ids[num]) {
            ids[num] = num;
            arr.push(110 + num);
        } else {
            i--;
        }
    }
    new Ajax("/api/purchase/change").keyvalue('ids', arr.join(',')).keyvalue('typid', typid).getJson(function (json) {
        changelist.empty();
        $.each(json, function (idx, val) {
            var surplus = Math.ceil(val.enddt - new Date().getTime() / 1000)
            if (surplus > 0) {
                changelist.append('<tr><td purname>' + val.name + '</td><td corpname>' + val.corpname + '</td><td enddt dateformat="' + val.enddt + '">还剩' + Math.ceil(surplus / 86400) + '天</td><td oper><a href="/purchase/details/' + val.id + '">立即报价</a></td></tr>');
            } else {
                changelist.append('<tr><td purname>' + val.name + '</td><td corpname>' + val.corpname + '</td><td enddt changelist="' + val.enddt + '"></td><td oper><a>已截止</a></td></tr>');
            }
        });
    });
});



